import tkinter
from mazibuild3D import *
from plotmaze import plot3DBase, plot3Dmaze
from astarrun3D import *
from tkinter import messagebox

if __name__ == '__main__':
    length = 20
    width = 20
    height = 10
    startPoint = (0, 0, 0)
    obstacleNum = int(length * width * 0.2)
    endPoint = (length - 1, width - 1, int(0.5 * height) - 1)

    obstacle = mazeBuild3D()  # 根据三维地图生成障碍物，这里调用之前存储的地图
    aStar = Astar(obstacle, Node(point(startPoint[0], startPoint[1], startPoint[2])),
                  Node(point(endPoint[0], endPoint[1], endPoint[2])), length,
                  width, height)
    path = aStar.run()  # 调用Astar类成员的启动函数，进行A*算法计算，返回路径点列表


    pathList = []
    if not path:
        plot3Dmaze(obstacle, startPoint, endPoint)
        tkinter.messagebox.showinfo("该地图未找到路径", "起始点或终止点与障碍物重合，或者实际上并没有通路")
        # 当起始点与终止点与障碍物重合，或者实际上并没有通路时报错
    else:
        for i in path:
            pathList.append((i.point.x, i.point.y, i.point.z))
        plot3DBase(obstacle, startPoint, endPoint, pathList)
        print(len(pathList))
        # 调用plotmaze 中的plot3DBase函数，进行路径绘制
